angular.module('market-referencepro', ['flow-div', 'slide-banner'])

.controller 'referenceproCtrl', ($location, $scope,$localStorage, $state, $http,showToast, $ionicHistory, $ionicViewSwitcher, $ionicPopup, paginationFactory, userData, $ionicActionSheet) ->
    $scope.$storage = $localStorage
    $scope.banners = [
        {img: 'img/market/ypk-banner1.png'}
        {img: 'img/market/ypk-banner2.png'}
        {img: 'img/market/ypk-banner3.png'}
    ]
    _.extend $scope,
        goBack: ->
            $ionicViewSwitcher.nextDirection('back')
            $ionicHistory.goBack()
        pick:() ->
            console.log $localStorage['goodItem']
            $localStorage['goodMarketDetail'] = undefined
            $localStorage['banners'] = undefined
            $localStorage['images'] = undefined
            getMarketDetail()
            $state.go 'tab.market-detail'


    getMarketDetail = ->
        $http.get('/updshop/',params:{action:'productinfo',id:$localStorage['goodItem'].id,isupk:'1',userid:userData.getToken()})
        .success (resp) ->
            if resp?.status == '0'
                $localStorage['goodMarketDetail'] = resp
                $localStorage['banners'] = resp.imgs
                $localStorage['images'] = resp.images
            else
                showToast '没有该商品'
        .error ->
            showToast '网络异常,请检查网络是否连接'
